import {
  CHANGE_INPUT_VALUE,
  CHANGE_LIST_VALUE,
  DELETE_LIST_ITEM,
  INIT_LIST_ACTION,
  GET_INIT_LIST,
} from "./actionTypes";
import axios from "axios";

// 修改input的value值
export const getInputChangeAction = (value) => ({
  type: CHANGE_INPUT_VALUE,
  value: value,
});

// 保存输入的这条todo
export const getButClickAction = () => ({
  type: CHANGE_LIST_VALUE,
});

// 删除这条todo
export const getDeleteItem = (index) => ({
  type: DELETE_LIST_ITEM,
  index,
});

export const initListAction = (data) => ({
  type: INIT_LIST_ACTION,
  data,
});

// redux-thunk 处理异步
export const getTodoList = () => {
  return (dispatch) => {
    axios.get("/list.json").then((res) => {
      const data = res.data;
      const action = initListAction(data);
      dispatch(action);
    });
  };
};

// redux-sage 处理异步
export const getInitList = (data) => {
  return ({
    type: GET_INIT_LIST,
  })
};
